home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / ex / ex13-11.c < prev    next >
C/C++ Source or Header  |  1990-05-15  |  1KB  |  40 lines

  1. // ex13-11.c -- Limitation of Object I/O
  2.  
  3. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/ex13-11.c,v 3.0 90/05/15 22:44:35 kgorlen Rel $
  4.  
  5. #include <fstream.h>
  6. #include <osfcn.h>
  7. #include "QLink.h"
  8. #include "LandVhcl.h"
  9. #include "OIOnih.h"
  10.  
  11. main()
  12. {
  13.     QLink* qlp = new LandVhcl(4.1, 12.0);
  14.     Link* lp = (QLink*) new LandVhcl(4.2, 12.0);
  15.     ofstream outstrm("badfile",ios::out,0664);  // UNIX protection
  16.                                                 // mode 0664
  17.     if (outstrm.fail()) {
  18.         cerr << "Failed to open badfile";
  19.         exit(1);
  20.     }
  21.     OIOnihout out(outstrm);
  22.     qlp->storeOn(out);
  23.     lp->storeOn(out);
  24.     outstrm.close();
  25.     LandVhcl* t = LandVhcl::castdown((Object*)qlp);
  26.     delete t;
  27.     t = LandVhcl::castdown((Object*)lp);
  28.     delete t;
  29.  
  30.     ifstream instrm("badfile");
  31.     if (instrm.fail()) {
  32.         cerr << "Failed to open badfile\n";
  33.         exit(1);
  34.     }
  35.     OIOnihin in(instrm);
  36.     qlp = QLink::readFrom(in);  // OK
  37.     cout << *qlp << endl;
  38.     lp = Link::readFrom(in);    // error: ambiguous downward cast
  39. }
  40.